package 简单多状态;

import java.util.Scanner;

public class test3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
        }
        System.out.println(deleteAndEarn(nums));
    }

    public static int deleteAndEarn(int[] nums) {
        int n = 10001;
        int[] arr = new int[n]; // 用来记录次数
        for (int i = 0; i < nums.length; i++) {
            arr[nums[i]] += nums[i];
        }

        int[] dp1 = new int[n];
        int[] dp2 = new int[n];
        dp1[0] = arr[0];

        for (int i = 1; i < n; i++) {
            dp1[i] = dp2[i-1]+arr[i];
            dp2[i] = Math.max(dp1[i-1],dp2[i-1]);
        }
        return Math.max(dp1[n-1], dp2[n-1]);
    }
}
